﻿<%@ WebHandler Language="C#" Class="AjaxServerResponse" %>

using System;
using System.Web;
using System.Web.SessionState;
using System.Data;

public class AjaxServerResponse : IHttpHandler, IRequiresSessionState
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        //context.Response.Charset = "utf-8";
        context.Response.Write(PostData(context, context.Request.Url.Authority));
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

    public string PostData(HttpContext contextParam, string strServerName)
    {
        string strReturn = string.Empty;
        string[] arrStrParams = contextParam.Server.UrlDecode(contextParam.Request["dataParam"]).Split(',');
        string strSign=contextParam.Request["sign"];
        
        //获取userid对应的sessionid
        ChBusiness.FlowOperation.SerialInstanceOperation sioTemp = new ChBusiness.FlowOperation.SerialInstanceOperation();
        string strWid = sioTemp.GetWidWithWname(arrStrParams[1]);
        string strAttrParmas = contextParam.Server.UrlEncode(arrStrParams[1]);
        switch (arrStrParams[0])
        {
            case "0"://办事指南---稍后要改成动态的
                strReturn = string.Format("BsznAppear.aspx?wid={0}", strWid);
                break;
            case "1"://办理流程
                //添加办理流程显示类型的判断 addby zhongjian 20100426
                DataTable dtTemp = sioTemp.GetWorkDefine("", arrStrParams[1]);
                if (dtTemp.Rows.Count > 0)
                {
                    string strFlagValue = dtTemp.Rows[0]["flagview"].ToString();
                    string strID = dtTemp.Rows[0]["id"].ToString();

                    switch (strFlagValue)
                    {
                        case "0"://审批流程
                            strReturn = string.Format("http://{0}{1}?wid={2}", strServerName,
                                System.Configuration.ConfigurationManager.AppSettings["ActivexDisplay"], strWid);
                            break;
                        case "1"://简易流程
                            strWid = sioTemp.GetWidWithWname(arrStrParams[1].ToString() + "(简)");
                            strReturn = string.Format("http://{0}{1}?wid={2}", strServerName,
                                System.Configuration.ConfigurationManager.AppSettings["ActivexDisplay"], strWid);
                            break;
                        case "2"://上传流程
                            strReturn = string.Format("ShowFlow.aspx?id={0}", strID);
                            break;
                        default:
                            break;
                    }
                }
                else
                {
                    strReturn = string.Format("http://{0}{1}?wid={2}", strServerName,
                        System.Configuration.ConfigurationManager.AppSettings["ActivexDisplay"], strWid);
                }
                break;
            case "2"://表格下载
                strReturn = string.Format("../Common/FileUploadView.aspx?datatype={0}", strAttrParmas);
                break;
            case "3"://在线申报---第三个参数对应iid
                string strUrl = "ShenBao.aspx";
                if (strSign == "1")
                    strUrl = "ShenBaoNew.aspx";
                if (arrStrParams[2].Trim() == "-1")
                {
                    long decValue = sioTemp.GetIIDWithEnterprise("", "", "");
                    //long decValue = WF_Business.SeedNumber.GetIIDWithEnterprise("", "", "");
                    strReturn = string.Format("{2}?flowname={0}&iid={1}", strAttrParmas, decValue, strUrl);
                }
                else//已有编号的前提下
                {
                    strReturn = string.Format("{2}?flowname={0}&iid={1}", strAttrParmas, arrStrParams[2], strUrl);

                }
                break;
            case "4"://结果公示
                strReturn = string.Format("JggsPage.aspx?wid={0}", strWid);
                break;
            case "5"://办件查询
                strReturn = string.Format("SerialQuery.aspx?wid={0}", strWid);
                break;
            case "6"://相关规定
                strReturn = string.Format("AppearXggd.aspx?wid={0}", strWid);
                break;
            case "7"://在线投诉
                //strReturn = string.Format("TsManager.aspx?wid={0}", strWid);
                strReturn = string.Format("TsOnline.aspx?wid={0}", strWid);
                break;
            default:
                break;
        }

        return strReturn;
    }

}